home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / mindos11.zip / DEVREAD.C < prev    next >
C/C++ Source or Header  |  1991-03-22  |  2KB  |  60 lines

  1. /*  devread.c   -- Read logical sectors */
  2. /*  Copyright 1988,1991 Steven W. Harrold. All rights reserved. */
  3. /*  $Header: DEVREAD.C_V 1.4 91/03/20 08:48:57 SWH Exp $ */
  4.  
  5. #include    "mfs.h"
  6. #include    "dev.h"
  7.  
  8. extern int Dstatus ;
  9.  
  10.  
  11. /*================================================================*/
  12. int devread (ddata, nsects, sectno, buffer)
  13. struct devdata  *ddata ;
  14. int             nsects ;
  15. int             sectno ;
  16. void            *buffer ;
  17. {
  18.     int         drive, head, track, sector ;
  19.     char        *buff = buffer ;
  20.  
  21.  
  22. /*  Perform a cursory check that the disk device has been initialized.
  23. */
  24.     if (!ddata->d_heads)
  25.     {
  26.         Dstatus = -1 ;
  27.         return Dstatus ;
  28.     }
  29.  
  30. /*  Perform the operation one sector at a time.  This eliminates the need
  31. **  for special handling of requests that span a track/head boundary.
  32. */
  33.     drive = ddata->d_drive ;
  34.     for (; nsects > 0; nsects--, sectno++)
  35.     {
  36.         track = sectno / (ddata->d_heads * ddata->d_sectors) ;
  37.         if (track >= ddata->d_tracks)
  38.             return -1 ;
  39.  
  40.         sector = (sectno % ddata->d_sectors) + 1;
  41.         head = (sectno % (ddata->d_heads * ddata->d_sectors)) /
  42.                ddata->d_sectors ;
  43.  
  44.         buffer = &buff[BLOCK_SIZE-(nsects*SECTOR_SIZE)];
  45.  
  46.         Dstatus = NEW_MEDIA ;
  47.         while (Dstatus == NEW_MEDIA)
  48.             Dstatus = BIOSDISK(_DISK_READ) ;
  49.         if (Dstatus)
  50.             return Dstatus ;
  51.  
  52.     } /* for nsects */
  53.  
  54.     return 0;
  55.  
  56. } /* devread() */
  57.  
  58.  
  59. /*---eof---*/
  60.